package com.zyd.shiro.controller.admin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zyd.shiro.persistence.beans.OrderAddress;
import com.zyd.shiro.business.service.MallOrderAddressService;

import com.zyd.shiro.framework.object.PageResult;
import com.zyd.shiro.framework.object.ResponseVO;
import com.zyd.shiro.util.ResultUtil;
/**
 * 控制器层
 * @author RookieWZW
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/orderAddress")
public class OrderAddressController {

	@Autowired
	private MallOrderAddressService orderAddressService;
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public ResponseVO findAll(){
		 return ResultUtil.success("查询成功",orderAddressService.findAll());
		
	}
	
	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResponseVO findOne(@PathVariable Integer id){
		return ResultUtil.success("查询成功", orderAddressService.findOne(id));
	}

	/**
	 * 根据OrderID查询
	 * @param id ID
	 * @return
	 */
	@RequestMapping(value="/findOneByOrderId/{id}",method=RequestMethod.GET)
	public ResponseVO findOneByOrderId(@PathVariable Integer id){
		return ResultUtil.success("查询成功", orderAddressService.findOneByOrderid(id));
	}
	
	/**
	 * 分页查询全部数据
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/{page}/{size}",method=RequestMethod.GET)
	public ResponseVO findPage(@PathVariable int page,@PathVariable int size){		
		Page<OrderAddress> pageList = orderAddressService.findPage(page, size);		
		return ResultUtil.success("查询成功",new PageResult(pageList.getTotalElements(), pageList.getContent() ) );	
	}
	
	/**
	 * 分页+多条件查询
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@RequestMapping(value="/{page}/{size}/{regionId}",method=RequestMethod.POST)
	public ResponseVO findSearch(@PathVariable int regionId ,@PathVariable int page,@PathVariable int size){
		Page<OrderAddress> pageList = orderAddressService.findSearch(regionId, page, size);
		return ResultUtil.success("查询成功",  new PageResult(pageList.getTotalElements(), pageList.getContent()) );		
	}
	
	/**
	 * 增加
	 * @param orderAddress
	 */
	@RequestMapping(value="/",method=RequestMethod.POST)
	public ResponseVO add(@RequestBody OrderAddress orderAddress  ){
		orderAddressService.add(orderAddress);			
		return ResultUtil.success("增加成功");
	}
	
	/**
	 * 修改
	 * @param orderAddress
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResponseVO update(@RequestBody OrderAddress orderAddress,@PathVariable Integer id ){
		orderAddress.setId(id);
		orderAddressService.update(orderAddress);		
		return ResultUtil.success("修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public ResponseVO delete(@PathVariable Integer id ){
		orderAddressService.delete(id);
		return ResultUtil.success("删除成功");
	}

	/**
	 * 根据区域id获得订单列表
	 */
	@RequestMapping(value="/getOrdersByRegionId/{id}",method=RequestMethod.POST)
	public ResponseVO findAllOrderByRegionId(@PathVariable Integer id){
		return ResultUtil.success("查询成功", orderAddressService.allRegionByRegionId(id));
	}



}
